package com.xuqm.sdhbwfu.app.viewmodel

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.xuqm.base.di.manager.HttpManager
import com.xuqm.base.extensions.showMessage
import com.xuqm.sdhbwfu.app.model.InspectionListModel
import com.xuqm.sdhbwfu.app.model.JobListModel
import com.xuqm.sdhbwfu.app.repository.Service
import com.xuqm.sdhbwfu.core.extensions.io_main
import com.xuqm.sdhbwfu.core.extensions.subscribeBy
import com.xuqm.sdhbwfu.core.viewModel.BaseViewModel

class JobProcessingViewModel : BaseViewModel() {

    private val _list = MutableLiveData<List<JobListModel>>()
    val list: LiveData<List<JobListModel>> = _list

    fun inspectionList(id: Int) {
        HttpManager.getApi(Service::class.java)
            .jobList(id)
            .io_main()
            .subscribeBy(
                {
                    _list.postValue(it)
                }, {
                    _list.postValue(null)
                    showMessage(it)
                }
            ).adds()
    }

    private val _status = MutableLiveData<InspectionListModel>()
    val status: LiveData<InspectionListModel> = _status
    fun inspectionConfirm(id: Int) {
        HttpManager.getApi(Service::class.java)
            .inspectionConfirm(id)
            .io_main()
            .subscribeBy(
                {
                    _status.postValue(it)
                }, {
                    _status.postValue(null)
                    showMessage(it)
                }
            ).adds()
    }

}